﻿using NPOI.XWPF.UserModel;

namespace Yz.Web.Controllers
{
    public class NPOIWordController : BaseController
    {
        private readonly IWebHostEnvironment _webHostEnvironment;
        public NPOIWordController(IWebHostEnvironment webHostEnvironment)
        {
            _webHostEnvironment = webHostEnvironment;
        }
        public void Index()
        {
            string filePath = _webHostEnvironment.WebRootPath + "/File2023/a.docx";
            using (FileStream fs = System.IO.File.OpenRead(filePath))
            {
                XWPFDocument docx = new XWPFDocument(fs);
                // 获取所有内容不为空的段落
                var pragraphList = docx.Paragraphs.Where(p => p.Text != "").ToList();
                foreach (var paragraph in pragraphList)
                {
                    var paragraphText = paragraph.ParagraphText;
                    ///文本内容
                    var textContent = paragraph.Text;
                    //内容分割（针对不同内容）
                    var runs = paragraph.Runs;

                }

            }

        }
    }
}
